package com.rm.freedrawsample.slice;

import com.rm.freedrawsample.AbilityDraw;
import com.rm.freedrawsample.AbilityDrawUtils;
import com.rm.freedrawsample.AbilityScrollable;
import com.rm.freedrawsample.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

/**
 * AbilityChooserSlice.
 *
 * @author author
 * @version version
 */
public class AbilityChooserSlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_chooser);
        getWindow().setStatusBarColor(getColor(ResourceTable.Color_colorPrimaryDark));
        findComponentById(ResourceTable.Id_draw_sample).setClickedListener(component -> {
            AbilityDrawUtils.setGoToAbilityDraw(true);
            startExampleAbility(AbilityDraw.class.getCanonicalName());
        });
        findComponentById(ResourceTable.Id_scrollable_sample).setClickedListener(component -> {
            startExampleAbility(AbilityScrollable.class.getCanonicalName());
        });
    }

    private void startExampleAbility(String withAbilityName) {
        Intent intent = new Intent();
        Operation opt = new Intent
                .OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(withAbilityName)
                .build();
        intent.setOperation(opt);
        startAbility(intent);
    }

}
